package com.flyoil.petromp.adapter.adapter_order;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.cnpc.fyimageloader.glide.GlideHelper;
import com.flyoil.petromp.R;
import com.flyoil.petromp.base.MyBaseAdapter;
import com.flyoil.petromp.entity.entity_order.OrderFilesEntity;
import com.flyoil.petromp.ui.activity.activity_matter.OrderSeeFileHtmlActivity;

/**
 * Created by Administrator on 2017/10/27.
 * 工单详情界面单个图片的适配器
 */

public class ItemImgOrderMessageAdapter extends MyBaseAdapter<OrderFilesEntity> {
    public ItemImgOrderMessageAdapter(Context context) {
        super(context);
    }

    @Override
    public View setView(int position, View convertView, ViewGroup parent) {
        Viewhoder viewhoder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_order_message_photo_item_layout, null);
            viewhoder = new Viewhoder(convertView);
            convertView.setTag(viewhoder);
        } else {
            viewhoder = (Viewhoder) convertView.getTag();
        }
        final OrderFilesEntity entity = (OrderFilesEntity) getItem(position);
        GlideHelper.showImage(context, entity.getUrl(), viewhoder.img_icon, R.mipmap.ima_loading_error_icon);
        viewhoder.img_icon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (entity.getPreviewer() != null) {
                    Intent intent = new Intent(context, OrderSeeFileHtmlActivity.class);
                    intent.putExtra("url", entity.getPreviewer());
                    context.startActivity(intent);
                }
            }
        });
        return convertView;
    }

    private class Viewhoder {
        private ImageView img_icon;

        public Viewhoder(View view) {
            this.img_icon = view.findViewById(R.id.img_item_order_message_photo_item_layout);
        }
    }
}
